Saving and restoring toolbar settings – PB Docs 2022 – PowerBuilder Library

您所在的位置:网站首页 pb profilestring Saving and restoring toolbar settings – PB Docs 2022 – PowerBuilder Library

Saving and restoring toolbar settings – PB Docs 2022 – PowerBuilder Library

2024-03-28 23:26| 来源: 网络整理| 查看: 265

Saving and restoring toolbar settings

You can save and restore the current toolbar settings using functions that retrieve information about your toolbar settings, and you can modify these settings.

GetToolbar and GetToolbarPos allow you to retrieve the current toolbar settings. SetToolbar and SetToolbarPos allow you to change the toolbar settings. The syntax you use for the GetToolbarPos and SetToolbarPos functions varies depending on whether the toolbar you are working with is floating or docked.

Floating toolbars

The position of a floating toolbar is determined by its x and y coordinates. The size of a floating toolbar is determined by its width and height.

When you code the GetToolbarPos and SetToolbarPos functions for a floating toolbar, you need to include arguments for the x and y coordinates and the width and height.

Docked toolbars

The position of a docked toolbar is determined by its docking row and its offset from the beginning of the docking row. For toolbars at the top or bottom, the offset for a docked toolbar is measured from the left edge. For toolbars at the left or right, the offset is measured from the top.

By default, the docking row for a toolbar is the same as its bar index. If you align the toolbar with a different border in the window, its docking row may change depending on where you place it.

When you code the GetToolbarPos and SetToolbarPos functions for a docked toolbar, you need to include arguments for the docking row and the offset.

Example

The example below shows how to use a custom class user object to manage toolbar settings. The user object has two functions, one for saving the current settings and the other for restoring the settings later on. Because the logic required to save and restore the settings is handled in the user object (instead of in the window itself), this logic can easily be used with any window.

The sample code shown below supports both fixed and floating toolbars.

Script for the window’s Open event

When the window opens, the following script restores the toolbar settings from an initialization file. To restore the settings, it creates a custom class user object called u_toolbar and calls the Restore function:

PowerBuilder 1234 // Create the toolbar NVOu_toolbar = create u_toolbar// Restore the toolbar positionsu_toolbar.Restore(this, "toolbar.ini", this.ClassName())

Script for the window’s Close event

When the window closes, the following script saves the toolbar settings by calling the Save function. Once the settings have been saved, it destroys the user object:

PowerBuilder 1234 // Save the toolbar stateu_toolbar.Save(this, "toolbar.ini", ClassName())// Destroy the toolbar NVOdestroy u_toolbar

Script for the Save function

The Save function has three arguments:

Win — provides the window reference

File — provides the name of the file where the settings should be saved

Section — identifies the section where the settings should be saved

The Save function uses the GetToolbar and GetToolbarPos functions to retrieve the current toolbar settings. To write the settings to the initialization file, it uses the SetProfileString function.

The Save function can handle multiple toolbars for a single menu. It uses the bar index to keep track of information for each toolbar:

PowerBuilder 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 // Store the toolbar settings for the passed windowinteger index, row, offset, x, y, w, hboolean visiblestring visstring, alignstring, titletoolbaralignment alignmentFOR index = 1 to 16  // Try to get the attributes for the bar.   IF win.GetToolbar(index, visible, alignment, ;   title)= 1 THEN      // Convert visible to a string   CHOOSE CASE visible   CASE true      visstring = "true"   CASE false         visstring = "false"      END CHOOSE    // Convert alignment to a string   CHOOSE CASE alignment         CASE AlignAtLeft!            alignstring = "left"   CASE AlignAtTop!      alignstring = "top"         CASE AlignAtRight!            alignstring = "right"         CASE AlignAtBottom!            alignstring = "bottom"         CASE Floating!            alignstring = "floating"   END CHOOSE    // Save the basic attributes      SetProfileString(file, section +  ;            String(index), "visible", visstring)            SetProfileString(file, section +  ;      String(index), "alignment", alignstring)      SetProfileString(file, section +  ;      String(index), "title", title)    // Save the fixed position   win.GetToolbarPos(index, row, offset)   SetProfileString(file, section +  ;      String(index), "row", String(row))   SetProfileString(file, section +  ;      String(index), "offset", String(offset))    // Save the floating position   win.GetToolbarPos(index, x, y, w, h)   SetProfileString(file, section +  ;      String(index), "x", String(x))   SetProfileString(file, section +  ;      String(index), "y", String(y))   SetProfileString(file, section +  ;      String(index), "w", String(w))    SetProfileString(file, section +  ;      String(index), "h", String(h))   END IFNEXT

Script for the Restore function

The Restore function has the same three arguments as the Save function. It uses the ProfileString function to retrieve toolbar settings from the initialization file. Once the settings have been retrieved, it uses the SetToolbar and SetToolbarPos functions to restore the toolbar settings.

Like the Save function, the Restore function can handle multiple toolbars for a single menu. It uses the bar index to keep track of information for each toolbar:

PowerBuilder 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 // Restore toolbar settings for the passed window integer index, row, offset, x, y, w, hboolean visiblestring visstring, alignstring, titletoolbaralignment alignment FOR index = 1 to 16  // Try to get the attributes for the bar.  IF win.GetToolbar(index, visible, alignment, ;    title)= 1 THEN    // Try to get the attributes from the .ini file    visstring = ProfileString(file, section +  ;      String(index), "visible", "")    IF visstring ; "" THEN      // Get all of the attributes      alignstring = ProfileString(file, section +  ;        String(index), "alignment", "left")      title = ProfileString(file, section +  ;        String(index), "title", "(Untitled)")      row = Integer(ProfileString(file, section +  ;        String(index), "row", "1"))      offset = Integer(ProfileString(file, ;        section + String(index), "offset", "0"))      x = Integer(ProfileString(file, section +  ;        String(index), "x", "0"))      y = Integer(ProfileString(file, section +  ;        String(index), "y", "0"))      w = Integer(ProfileString(file, section +  ;        String(index), "w", "0"))      h = Integer(ProfileString(file, section +  ;        String(index), "h", "0"))       // Convert visstring to a boolean      CHOOSE CASE visstring      CASE "true"        visible = true      CASE "false"        visible = false      END CHOOSE       // Convert alignstring to toolbaralignment      CHOOSE CASE alignstring      CASE "left"        alignment = AlignAtLeft!      CASE "top"        alignment = AlignAtTop!      CASE "right"        alignment = AlignAtRight!      CASE "bottom"        alignment = AlignAtBottom!      CASE "floating"        alignment = Floating!      END CHOOSE       // Set the new position      win.SetToolbar(index, visible, alignment, title)      win.SetToolbarPos(index, row, offset, false)      win.SetToolbarPos(index, x, y, w, h)    END IF  END IFNEXT



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3